//
//  XMSchoolSelectView.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/5/21.
//

#import "XMSchoolSelectView.h"

@interface XMSchoolSelectView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tbl;

@end

@implementation XMSchoolSelectView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.backgroundColor = kColorHEX(0xF0F0F0);
    [self addSubview:self.tbl];
}

#pragma mark - Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return KScaleWidth(37.0);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, KScaleWidth(37.0))];
    headView.backgroundColor = kColorHEX(0xF0F0F0);
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), 0, headView.width - KScaleWidth(16.0)*2, headView.height) font:KFontSize(15.0) textColor:kColorHEX(0x666666)];
    titleLabel.text = @"30天内学校只可修改一次";
    [headView addSubview:titleLabel];
    return headView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return KScaleWidth(45.0);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellName = @"XMSchoolSelectCellName";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellName];
        cell.textLabel.font = KFontSize(17.0);
        cell.textLabel.textColor = kColorHEX(0x333333);
        cell.detailTextLabel.font = KFontSize(15.0);
        cell.detailTextLabel.textColor = kColorHEX(0x666666);
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = @[@"学校", @"院系", @"入学时间", @"学历"][indexPath.row];
    cell.detailTextLabel.text = @[@"北京大学", @"光华管理学院", @"2017/09/01", @"本科"][indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - Init
- (UITableView *)tbl {
    if (!_tbl) {
        _tbl = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.width, KScaleWidth(self.height))];
        _tbl.delegate = self;
        _tbl.dataSource = self;
        _tbl.backgroundColor = kColorHEX(0xF0F0F0);
        if (@available(iOS 15.0, *)) {
            _tbl.sectionHeaderTopPadding = 0;
        } else {
            _tbl.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            // Fallback on earlier versions
        }
        UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tbl.width, KScaleWidth(14.0))];
        footView.backgroundColor = kColorHEX(0xffffff);
        _tbl.tableFooterView = footView;
    }
    return _tbl;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
